package algocasts;

public class P13_isPalindrome {

    public boolean isPalindrome_String(int num) {
        String s = String.valueOf(num);
        int left = 0, right = s.length() - 1;
        while (left < right) {
            if (s.charAt(left) != s.charAt(right)) return false;
            left++;
            right--;
        }
        return true;
    }

    public boolean isPalindrome(int num) {
        if (num < 0) return false;
        int tmp = num;
        long reverseNum = 0;
        while (tmp != 0) {
            int n = tmp % 10;
            reverseNum = reverseNum * 10 + n;
            tmp /= 10;
        }
        return num == reverseNum;
    }

    public static void main(String[] args) {
        P13_isPalindrome solution = new P13_isPalindrome();
        System.out.println(solution.isPalindrome_String(112211));
        System.out.println(solution.isPalindrome(112211));
    }
}
